home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 436_01 / inalpha.c < prev    next >
Text File  |  1994-10-07  |  6KB  |  248 lines

  1. /*************************************************************************
  2.     Source file:  INALPHA.C
  3.  
  4.     INCON alpha input handler.
  5.  
  6.       Editor:  Microsoft Works 1.0, Microsoft Word 4.0
  7.     Compiler:  Borland Turbo C 2.01
  8.  
  9.     INCON source files and the object and library files created from
  10.     them are:
  11.         Copyright (c) 1993-94, Richard Zigler.
  12.     You may freely distribute unmodified source, object, and library
  13.     files, and incorporate them into your own non-commercial software,
  14.     provided that this paragraph and the program name and copyright
  15.     strings defined in INCON.C are included in all copies.
  16. *************************************************************************/
  17.  
  18. #include <conio.h>
  19. #include <ctype.h>
  20. #include <string.h>
  21. #include "indefs.h"                            /* globals and definitions            */
  22. #include "incon.h"                            /* state definitions                    */
  23. #include "indecl.h"                            /* public utility routines            */
  24.  
  25. int pascal hAlphaField( STATES State, register int Pos )
  26. {
  27. register int    s_ptr;
  28. int                max_length    = StrLength - 1,
  29.                     max_width    = Width - 1;
  30.  
  31. switch( State )
  32.     {
  33.     case stError:
  34.         break;
  35.  
  36.     case stQuit:                                /* [Enter] -- end input                */
  37.  
  38.         Chr = StrLength < Prec ? -1 : 0 ;
  39.         More = NO;
  40.         break;
  41.  
  42.     case stInit:                                /* field initialization                */
  43.  
  44.         if ( !Flags.Hide && !Flags.Scroll )
  45.             Pos = StrLength;
  46.         break;
  47.  
  48.     case stFieldClear:                        /* [Esc] -- clear field or exit    */
  49.  
  50.         if ( EscSet || *OutStr == '\0' )
  51.             More = NO;
  52.         else
  53.             {
  54.             *OutStr = '\0';
  55.             Pos = StrLength = 0;
  56.             ++Update;
  57.             }
  58.         break;
  59.  
  60.     case stDeleteCharLeft:                    /* [Backspace] -- delete left        */
  61.  
  62.         if ( Pos )
  63.             {
  64.             if ( Pos > max_length )
  65.                 {
  66.                 putch( BS );
  67.                 putch( Fill );
  68.                 OutStr[--Pos] = '\0';
  69.                 --StrLength;
  70.                 --Move;
  71.                 }
  72.             else if ( Pos == max_length )
  73.                 goto __TruncateAtCursor;
  74.             else
  75.                 {
  76.                 --Pos;
  77.                 goto __MoveCharsToCursor;
  78.                 }
  79.             }
  80.         break;
  81.  
  82.     case stMoveToStart:                        /* [Home] -- start of field        */
  83.  
  84.         if ( Pos )
  85.             {
  86.             Pos = 0;
  87.             --Move;
  88.             }
  89.         break;
  90.  
  91.     case stMoveCharLeft:                        /* [Left Arrow] -- move char lt    */
  92.  
  93.         if ( Pos )
  94.             {
  95.             --Pos;
  96.             --Move;
  97.             }
  98.         break;
  99.  
  100.     case stMoveCharRight:                    /* [Right Arrow] -- move char rt    */
  101.  
  102.         if ( Pos < StrLength && Pos < max_width )
  103.             {
  104.             ++Pos;
  105.             ++Move;
  106.             }
  107.         break;
  108.  
  109.     case stMoveToEnd:                            /* [End] -- end of field            */
  110.  
  111.         if ( Pos < StrLength && Pos < max_width )
  112.             {
  113.             Pos = StrLength;
  114.             ++Move;
  115.             }
  116.         break;
  117.  
  118.     case stMoveWordLeft:                        /* [Ctrl Left] -- move word lt    */
  119.  
  120.         if ( Pos )
  121.             {
  122.             Pos = WordLeft( Pos, OutStr, ' ' );
  123.             --Move;
  124.             }
  125.         break;
  126.  
  127.     case stMoveWordRight:                    /* [Ctrl Right] -- move word rt    */
  128.  
  129.         if ( Pos < StrLength && Pos < max_width )
  130.             {
  131.             Pos = WordRight( Pos, OutStr, ' ' );
  132.             ++Move;
  133.             }
  134.         break;
  135.  
  136.     case stDeleteWordLeft:                    /* [Ctrl L] -- delete word left    */
  137.  
  138.         if ( !Flags.Hide && Pos > (Flags.Scroll ? FieldMin + 1 : FieldMin) )
  139.             {
  140.             s_ptr = Pos;
  141.             Pos = WordLeft( Pos, OutStr, ' ' );
  142.             goto __DeleteWord;
  143.             }
  144.         break;
  145.  
  146.     case stDeleteWordRight:                    /* [Ctrl R] -- delete word right    */
  147.  
  148.         if ( !Flags.Hide && Pos < StrLength )
  149.             {
  150.             s_ptr = WordRight( Pos, OutStr, ' ' );
  151.  
  152. __DeleteWord:
  153. ;
  154.             memcpy( OutStr + Pos, OutStr + s_ptr, StrLength - s_ptr + 1 );
  155.             StrLength -= (s_ptr - Pos);
  156.             ++Update;
  157.             }
  158.         break;
  159.  
  160.     case stDeleteToEnd:                        /* [Ctrl End] -- clear to end        */
  161.  
  162.         if ( Pos < StrLength )
  163.             goto __TruncateAtCursor;
  164.         break;
  165.  
  166.     case stDeleteToStart:                    /* [Ctrl Home] -- clear to start    */
  167.  
  168.         if ( Pos )
  169.             {
  170.             memcpy( OutStr, OutStr + Pos, StrLength - Pos + 1 );
  171.             StrLength -= Pos;
  172.             Pos = 0;
  173.             ++Update;
  174.             }
  175.         break;
  176.  
  177.     case stDeleteAtCursor:                    /* [Del] -- delete at cursor        */
  178.  
  179.         if ( StrLength )
  180.             {
  181.             if ( Pos < max_length )
  182.                 {
  183. __MoveCharsToCursor:
  184. ;
  185.                 memcpy( OutStr + Pos, OutStr + Pos + 1, StrLength - Pos );
  186.                 --StrLength;
  187.                 ++Update;
  188.                 }
  189.             else if ( Pos == max_length )
  190.                 {
  191. __TruncateAtCursor:
  192. ;
  193.                 OutStr[Pos] = '\0';
  194.                 StrLength = Pos;
  195.                 ++Update;
  196.                 }
  197.             }
  198.         break;
  199.  
  200.     case stExitPlus:                            /* [Keypad +] -- special exit        */
  201.     case stExitMinus:                            /* [Keypad -] -- special exit        */
  202.  
  203.         /* convert to + or - and fall through to stCharMatch                    */
  204.  
  205.         Chr = (State == stExitPlus) ? '+' : '-' ;
  206.  
  207.     case stCharMatch:                            /* see if entry matches field        */
  208.  
  209.         if ( !iscntrl( Chr ) )
  210.             {
  211.             if ( Flags.Type == UPPER )
  212.                 Chr = toupper( Chr );        /* convert alpha to uppercase        */
  213.             if ( InBegin )                        /* if first character entered        */
  214.                 {
  215.                 *(WORD *)OutStr = Chr;        /* put Chr and '\0'                    */
  216.                 StrLength = Pos = 1;
  217.                 if ( Flags.Hide )                /* if hidden input,                    */
  218.                     putch( ' ' );                /*   update display                    */
  219.                 ++Update;
  220.                 }
  221.             else if ( Pos == StrLength || Pos == max_width )    /* at end    */
  222.                 {
  223.                 if ( StrLength >= Width )                                /* at max    */
  224.                     --StrLength;
  225.                 putch( Flags.Hide ? ' ' : Chr );
  226.                 *(WORD *)(OutStr + Pos++) = Chr;
  227.                 ++StrLength;
  228.                 ++Update;
  229.                 }
  230.             else if ( StrLength < Width )            /* cursor within string        */
  231.                 {
  232.                 memmove(OutStr + Pos + 1,OutStr + Pos,StrLength - Pos + 1);
  233.                 OutStr[Pos++] = (char)Chr;
  234.                 ++StrLength;
  235.                 ++Update;
  236.                 }                                    /* else (InBegin)                        */
  237.          }                                        /* if (!iscntrl())                    */
  238.         else
  239.             State = stError;
  240.         break;
  241.     }                                                /* switch()                                */
  242. if ( Pos >= Width )
  243.     Pos = Width - 1;
  244. return( Pos );
  245. }
  246.  
  247. /**** EOF:  INALPHA.C ****/
  248.